import request from '@/utils/request.js'
import store from '@/store/'// 就是组件中的this.store,这不是组件不能用映射
const getAllChannelListApi = () => {
  return request({
    url: '/v1_0/user/channels',
    headers: {
      Authorizations: `Bearer ${store.state.token}`
    }
  })
}
// 文章_获取列表
const articlesListAPI = ({ channelId, timestamp = Date.now() }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    },
    isAuth: false
  })
}
// 文章-不感兴趣
const articleDislikeAPI = ({ artid }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: artid
    },
    headers: {
      Authorization: `Bearer ${store.state.token}`
    }
  })
}
// 文章举报
const articleReportsAPI = ({ artid, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: artid,
      type: type,
      remark: remark
    },
    headers: {
      Authorization: `Bearer ${store.state.token}`
    }
  })
}
// 接口方法, 只负责调用一个接口, 返回一个Promise对象
// 频道 - 所有频道
const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
// 频道 - 用户已选频道
const userChannelAPI = () => request({
  url: '/v1_0/user/channels'
})
// 频道 - 更新已选
const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}
// 按需导出
export { getAllChannelListApi, articlesListAPI, articleDislikeAPI, articleReportsAPI, allChannelListAPI, userChannelAPI, updateChannelAPI }
